﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interpreter
{
	internal class Token
	{
		private Metadata metadata;
		private int fileIndex;
		private int lineIndex;
		private int columnIndex;

		public Token(Metadata data, int fileId, int lineIndex, int columnIndex)
		{
			this.metadata = data;
			this.fileIndex = fileId;
			this.lineIndex = lineIndex;
			this.columnIndex = columnIndex;
		}

		public int LineNum { get { return this.lineIndex + 1; } }
		public int ColumnNum { get { return this.columnIndex + 1; } }

		private FileInfo FileInfo
		{
			get
			{
				return this.metadata.RawSource[this.fileIndex];
			}
		}

		public string FileName
		{
			get
			{
				FileInfo fileInfo = this.FileInfo;
				if (fileInfo != null)
				{
					return fileInfo.Name;
				}
				return null;
			}
		}

		public string Line
		{
			get
			{
				FileInfo fileInfo = this.FileInfo;
				if (fileInfo != null)
				{
					return fileInfo.Lines[this.lineIndex].Replace("\t", "    ");
				}
				return null;
			}
		}

		public string ColumnPointer
		{
			get
			{
				FileInfo fileInfo = this.FileInfo;
				if (fileInfo != null)
				{
					string output = "";
					string line = fileInfo.Lines[this.lineIndex];
					for (int i = 0; i < this.columnIndex; ++i)
					{
						if (line[i] == '\t')
						{
							output += "    ";
						}
						else
						{
							output += " ";
						}
					}
					return output + "^";
				}
				return null;
			}
		}
	}
}
